#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string.h>
using namespace std;

int main() {
	int n = 0, m = 0, maxn1 = 0;
	cin >> n;
	int arr[101];
	memset(arr, 0, sizeof(arr) / sizeof(int));
	for (int i = 0; i < n; i++) {
		int a = 0, b = 0;
		cin >> a >> b;
		arr[b] += a;
		if (maxn1 < b) {
			maxn1 = b;
		}
	}

	cin >> m;
	for (int i = 0; i < m; i++) {
		int a = 0, b = 0;
		cin >> a >> b;
		arr[b] += a;
		if (maxn1 < b) {
			maxn1 = b;
		}
	}
	for (int i = maxn1; i >= 0; i--) {
		if (arr[i] != 0) {
			cout << arr[i] << " " << i << endl;
		}
	}
	return 0;
}